<%@page import="com.sinba.common.system.service.ITransactionRecordService"%>
<%@page import="com.sinba.common.business.dto.SellQueryDTO"%>
<%@page import="com.sinba.common.business.service.ISellService"%>
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.user.dto.AccountDTO"%>
<%@page import="com.sinba.common.user.service.IAccountService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
if(session.getAttribute("password2")==null){
	/* response.sendRedirect( "login2.jsp?pageUrl=user/sell.jsp");
	return; */
}

ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
ISellService sellService = (ISellService)ac.getBean("sellService");
SellQueryDTO qdto = new SellQueryDTO();
qdto.setSellUser((String)session.getAttribute("loginName"));
int pages = 1;
String sidx = "createTime";
String sord="desc";
if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
	pages = Integer.parseInt(request.getParameter("pages"));
}
int rows = 10;
int start = ( pages - 1 ) * rows;
qdto.setStart( start );
qdto.setLimit( rows );
PageDTO pageDTO = sellService.findSellPage(qdto, sord, sidx);
if(pageDTO!=null){
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
}
request.setAttribute("pageDTO",pageDTO);

ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
Double balance = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),"Dynamic");
request.setAttribute("balance",balance);
Double result = balance/100;
Long multiple  = result.longValue();
request.setAttribute("multiple",multiple);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><fmt:message key="i18n.accountZhuanZhang"/>-<fmt:message key="i18n.title"/> </title>
<link rel="shortcut icon" href="../index/favicon.png" />
<link href="../skin/skin1/css/subPage.css" rel="stylesheet">
<link rel="stylesheet" href="css/sub_page_main_style.css" />
</head>
<body style="background:#ede3d1;height:800px;">
	<div class="account">
	<div class="top"><fmt:message key="i18n.tradeMg" />&gt; <fmt:message key="i18n.mySells" /></div>
	<!-- <div class="left"></div> -->
    <div class="right" style="margin: 0px;">
      <%-- <form id="sell_form" action="sell!sell.action" method="post">
	 	<input type="hidden" name="pageUrl" value="sell.jsp" />
	 	<input type="hidden" name="sellDTO.sellUser" value="${session.loginName}" />
	 	<input type="hidden" value="Dynamic" name="sellDTO.sellType">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<!-- <td align="right" width="15%">
					<p>
					<input type="radio" value="Static" name="sellDTO.sellType" checked="checked">静态
					<input type="radio" value="Dynamic" name="sellDTO.sellType">动态
					</p> 
				</td> -->
				<td align="left" width="35%" style="color:red;font-weight: 200">
					<fmt:message key="i18n.zhanghuBalance"/>：<fmt:formatNumber value="${balance}" pattern="#0"/>
					&nbsp;&nbsp;&nbsp;&nbsp;
					(<fmt:message key="i18n.sellTip1"/>)
				</td>
			</tr>
			<tr>
				<td align="left" width="35%" style="font-weight: 200">
				<fmt:message key="i18n.acceptBuyMoney" />:
				<input name="sellDTO.sellMoney" id="sellmoney" type="text" value="30000"/>
				<input name="sellDTO.sellPrice" id="sellPrice" type="text" value="0.1"/>
				<input class="ty_an" type="submit" value="<fmt:message key="i18n.sellConfirm"/>"/></td>
			</tr>
		</table>
	  </form> --%>
      <br><br>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
			<%-- <th scope="col"><fmt:message key="i18n.xuhao" /></th> --%>
	        <%-- <th scope="col"><fmt:message key="i18n.memberNumber" /></th> --%>
			<th scope="col"><fmt:message key="i18n.aid.createData" /></th>
			<!-- <th scope="col">帮助类型</th> -->
			<th scope="col"><fmt:message key="i18n.status" /></th>
			<th scope="col"><fmt:message key="i18n.maichugushu" /></th>
			<th scope="col"><fmt:message key="i18n.sellPirce" /></th>
			<th scope="col"><fmt:message key="i18n.alreadySell" /></th>
			<th scope="col"><fmt:message key="i18n.shengyugushu" /></th>
			<th scope="col"><fmt:message key="i18n.remark" /></th>
			<%-- <th scope="col"><fmt:message key="i18n.operation" /></th> --%>
        </tr>
        <c:if test="${pageDTO.totalSize eq 0}">
		<tr><td colspan="9" align="center"><fmt:message key="i18n.noData"/>
		</td></tr>
		</c:if>	
		<c:if test="${pageDTO.totalSize ne 0}">
			<c:forEach items="${pageDTO.data}" var="data">
			<tr>
				<%-- <td>${data.id }</td> --%>
				<%-- <td>${data.sellUser }</td> --%>
				<td><fmt:formatDate value="${data.createTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
				<%-- <td>
					<c:choose>
						<c:when test="${data.sellType eq Static}">
							静态
						</c:when>
						<c:otherwise>
							动态
						</c:otherwise>
					</c:choose>
				</td> --%>
				<td>
				<c:choose>
				 
				    <c:when test="${data.status eq 1}"> 
					   <span style="color:#008AD4;"><fmt:message key="i18n.tranIng" /></span>
				   </c:when>
				   <c:when test="${data.status eq 2}"> 
					    <span style="color:green;"><fmt:message key="i18n.tranSuccess" /></span>
				   </c:when>
				   <c:when test="${data.status eq 3}"> 
				   		<span style="color:red;"><fmt:message key="i18n.cleaned" /></span>
				   </c:when>
				   <c:otherwise>
					   <span style="color:blue;"><fmt:message key="i18n.Queue" /></span>
				   </c:otherwise>
				</c:choose>
				</td>
				<td>${data.sellMoney }</td>
				<td>${data.sellPrice }</td>
				<td>${data.sellMoney- data.surplusMoney}</td>
				<td>
					${data.surplusMoney}
				</td>
				<td>
					${data.remark}
				</td>
				<%-- <td>
					<c:if test="${data.status eq 0}">
						<a style="cursor:hand;" onclick="clean('${data.id}')">[<fmt:message key="i18n.clean"/>]</a>
					</c:if>
					<c:if test="${data.status ne 0 and data.status ne 3}">
						<a style="cursor:hand;" href="matchSell.jsp?status=0">[<fmt:message key="i18n.detail"/>]</a>
					</c:if>
				</td> --%>
			</tr>
			</c:forEach>
		</c:if>
      </table>
      	<!-- 分页 start -->
		<div class="page">
		<div class="page_r">
			<ul>
				<li><a href="sell.jsp?pages=1"><fmt:message key="i18n.firstPage"/></a></li>
				<c:if test="${pageDTO.page!=1}">
					<li><a href="sell.jsp?pages=${pageDTO.page-1}"><fmt:message key="i18n.upPage"/></a></li>
				</c:if>
				<li><a>${pageDTO.page}/${pageDTO.total}</a></li>
				<c:if test="${pageDTO.page+1<=pageDTO.total}">
					<li><a href="sell.jsp?pages=${pageDTO.page+1}"><fmt:message key="i18n.nextPage"/></a></li>
				</c:if>
				<li><a href="sell.jsp?pages=${pageDTO.total}"><fmt:message key="i18n.endPage"/></a></li>
				<li><a><fmt:message key="i18n.total"/>${pageDTO.totalSize}<fmt:message key="i18n.tiao"/></a></li>
			</ul>
		</div>
		</div>
		<!-- 分页 end  -->
    </div>
  </div>
  
<script type="text/javascript" src="../scripts/jquery/jquery-1.4.2.min.js"></script>
<script>
	$(function(){
		$("#sell_form").submit(function(){
			var sellmoney = $("#sellmoney").val();
			if(isNaN(sellmoney)){
				alert('请输入正确的数值！');
			}else{
				 var pattern = /^[1-9]\d*00$/; 
				 if(pattern.test(sellmoney)){
					 if(parseInt(sellmoney)>=500){
						 return true;
					 }else{
						 alert('金额不能小于500元');
					 }
				 }else{
					 alert("请输入100的倍数");
				 }
			}
			return false;
		});
	});
	function clean(id){
		var c = confirm("取消了需要重新排队，是否要取消？");
		if(c){
			window.location.href="sell!clean.action?sellDTO.id="+id+"&pageUrl=sell.jsp"
		}
	}
</script>
</body>
</html>